package com.yanchangapp.adapter._n_manage;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yanchangapp.R;
import com.yanchangapp.model.bean.LookLinkManBean;

import java.util.List;

/**
 * Created by apple on 2019-10-15.
 * description:查看关联员工的分组 Adapter....
 */
public class GroupLookLinkManAdapter extends BaseQuickAdapter<LookLinkManBean, BaseViewHolder> {

    public GroupLookLinkManAdapter(@Nullable List<LookLinkManBean> data) {
        super(R.layout.item_look_link_man, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, LookLinkManBean item) {
        int position = helper.getAdapterPosition();
        String levelName = "";
        String currentLevel = item.getLevelName();
        if (position == 0){
            levelName = currentLevel;
        }else {
            String beforeLevelName = mData.get(position -1).getLevelName();
            if (!beforeLevelName.equals(currentLevel)){
                levelName = currentLevel;
            }
        }

        TextView tvGroupName = helper.getView(R.id.tvGroupName);
        // 设置分组
        if (TextUtils.isEmpty(levelName)){
            tvGroupName.setVisibility(View.GONE);
        }else {
            tvGroupName.setVisibility(View.VISIBLE);
            tvGroupName.setText(levelName);
        }
        // 设置员工姓名
        helper.setText(R.id.tvItemName,item.getName());
        // 对可操作进行校验....
        CheckBox checkBox = helper.getView(R.id.checkbox);
        ImageView ivPen = helper.getView(R.id.ivPen);

        boolean isEnable;
        if (item.getGenerate() == null){
            isEnable = true;
        }else {
            if (item.getGenerate()){
                isEnable = false;
            }else {
                isEnable = true;
            }
        }
        if (isEnable){
            ivPen.setVisibility(View.VISIBLE);
            Integer predictTime = item.getPredictTime();
            String timeShow = "期限";
            if (predictTime != null){
                timeShow = predictTime+"天";
            }
            helper.setText(R.id.tvTime,timeShow);
            helper.addOnClickListener(R.id.llTime).addOnClickListener(R.id.checkbox);
            checkBox.setChecked(item.isSelected());
        }else {
            helper.setText(R.id.tvTime,"已做计划");
            ivPen.setVisibility(View.GONE);
        }
        // 设置是否可以操作....
        checkBox.setEnabled(isEnable);
        helper.addOnClickListener(R.id.llItem);

    }
}
